<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>角色管理</title>
    <#include "../common/link.ftl" >
    <script>
        $(function () {
            $(".btn_delete").click(function () {
                // 获取删除按钮绑定的 id
                var id = $(this).data('id');

                // 发送删除请求 使用消息提醒插件
                $.messager.confirm("警告","是否确认删除",function(){
                    $.get('/classinfo/delete.do',{id:id},handlerMessage)
                })

            });




            $(".btn_redirect").click(function () {

                // 清除模态框数据
                $("#editModal input").val("");

                // 获取当前编辑数据
                var json = $(this).data('json');
                // console.log(json.id);


                // 把值赋给模态框对应的 value
                if(json){
                    $('#editForm input[name=name]').val(json.name);
                    $('#editForm input[name=id]').val(json.id);
                    $('#editForm input[name=number]').val(json.number);
                    $('#selectBindEmployeeName').val(json.employee_id);
                }

                // 打开模态框
                $("#editModal").modal('show');
            });
        });

    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl" >
    <!--菜单回显-->
    <#assign currentMenu="classinfo">
    <#include "../common/menu.ftl" >
    <div class="content-wrapper">
        <section class="content-header">
            <h1>班级管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <!--高级查询--->
                    <form class="form-inline" id="searchForm" action="/classinfo/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label for="keyword">关键字:</label>
                            <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                                   placeholder="请输入班级名称">
                        </div>
                        <div class="form-group">
                            <label for="dept">班主任 :</label>
                            <select class="form-control" id="dept" name="employee_id">
                                <option value="-1">全部</option>
                                <#list employees as employee>
                                <option value="${employee.id}" >${employee.name}</option>
                                </#list>
                            </select>
                            <script>
                                $("#dept option[value='${qo.employee_id!}']").prop("selected", true);
                            </script>
                        </div>
                        <button id="btn_query" class="btn btn-primary">
                            <span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <a href="#" class="btn btn-success btn_redirect">
                            <span class="glyphicon glyphicon-plus"></span> 添加</a>
                    </form>

                    <table class="table table-striped table-hover" >
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>班级名称</th>
                            <th>班级人数</th>
                            <th>班主任</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <#list pageInfo.list as classinfo >
                           <tr>
                               <td>${classinfo?index+1}</td>
                               <td>${(classinfo.name)!}</td>
                               <td>${(classinfo.number)!}</td>
                               <td>${(classinfo.emp.name)!}</td>
                               <td>
                                   <#--<a href="/role/input.do?id=${management.id}" class="btn btn-info btn-xs btn_redirect">-->
                                       <#--<span class="glyphicon glyphicon-pencil"></span> 编辑-->
                                   <#--</a>-->
                                   <a href="#" class="btn btn-info btn-xs btn_redirect" data-json='${classinfo.json}'>
                                       <span class="glyphicon glyphicon-pencil"></span> 编辑
                                   </a>
                                   <a href="#" class="btn btn-danger btn-xs btn_delete" data-id = "${classinfo.id}" >
                                       <span class="glyphicon glyphicon-trash"></span> 删除
                                   </a>
                               </td>
                           </tr>
                        </#list>
                    </table>

                    <!--分页-->
                    <#include "../common/page.ftl" >
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl" >
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="editModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加班级信息</h4>
            </div>
            <form class="form-horizontal" action="/classinfo/saveOrUpdate.do" method="post" id="editForm">
                <div class="modal-body">

                    <input type="hidden" value="" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">班级名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name" value=""
                                   placeholder="请输入班级名称">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">班级人数：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" id="number" name="number" value=""
                                   placeholder="请输入班级人数">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">班主任：</label>
                        <div class="col-sm-6">

                            <select class="form-control" name="employee_id" id="selectBindEmployeeName" >
                                <#list employees as employee>
                                <option value="${employee.id}" >${employee.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>

                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
            <script>
                $(function () {
                    $("#editModal").ajaxForm(handlerMessage)
                })
            </script>
        </div>
    </div>
</div>
</body>
</html>
